package gui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JColorChooser;
import javax.swing.JComponent;
import javax.swing.JLabel;

public class ColorButton extends JComponent {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Color col;
	public ColorButton(String desc,Color c) {
		col = c;
		setLayout(new FlowLayout());
		add(new JLabel(desc));
		add(new ColorTile());
	}
	public void setColor(Color c) {
		col = c;
		repaint();
	}
	public Color getColor() {
		return col;
	}
	private class ColorTile extends JComponent implements MouseListener {
		public ColorTile() {
			addMouseListener(this);
		}
		public Dimension getPreferredSize() {
			return new Dimension(30,30);
		}
		public void paint(Graphics g) {
			g.setColor(col);
			g.fillRect(0,0,getWidth(),getHeight());
		}
		public void mouseClicked(MouseEvent e) {
			setColor(JColorChooser.showDialog(this, "Choose Ball Color", getColor()));
		}
		public void mouseEntered(MouseEvent e) {
			// TODO Auto-generated method stub
			
		}
		public void mouseExited(MouseEvent e) {
			// TODO Auto-generated method stub
			
		}
		public void mousePressed(MouseEvent e) {
			// TODO Auto-generated method stub
			
		}
		public void mouseReleased(MouseEvent e) {
			// TODO Auto-generated method stub
			
		}
	}
	
}
